<?php
define('DB_REGISTER_QUERYS',true);

/**
* PXFDataBase
*
*/
class PXFDataBase
{
	private $querys = array();	
	public $host 			= PXFConfig::DB_HOST;
	public $user 			= PXFConfig::DB_USER;
	public $pass 			= PXFConfig::DB_PASS;
	public $database 	= PXFConfig::DB_DB;

	private function __construct()
	{
		$this->connect();
	}

	public static function getInstance()
	{
		static $ins = null;		
		if(is_null($ins))
		{
			$ins = new PXFDataBase();
		}
		return $ins;
	}

	public function query($query)
	{
		// print $query . '<br>'; 
		if(DB_REGISTER_QUERYS)
		{
			$this->querys[] = $query;
		}
		return mysql_query($query);
	}


	public function fetch($result)
	{
		return mysql_fetch_assoc($result);
	}

	public function select($query)
	{
		return  $this->query($query);
	}

	public function update($query)
	{
		$result = $this->query($query);
		if($result) return mysql_affected_rows();
	}

	public function insert($query)
	{
		$result = $this->query($query);
		if($result) return mysql_insert_id();
	}

	public function delete($query)
	{
		$result = $this->query($query);
		if($result) return mysql_affected_rows();
	}

	private function connect()
	{
		$this->conn = mysql_connect($this->host,$this->user,$this->pass);
		$this->db = mysql_select_db($this->database);
	}

	public function dump()
	{
		print '<pre>';
		foreach($this->querys as $query)
		{
			echo $query ."\n";
		}
		print '</pre>';
	}
}

?>
